#include "mainwindow.h"
#include "rtc.h"
#include <QApplication>
#include "cv_yolo.h"
#include "modules/video_capture/video_capture.h"
#include "video_source_impl.h"
#include <QString>
#include <QDebug>
#include "modules/video_capture/video_capture_factory.h"
#include "rtc_base/logging.h"
#include "camera_video_sink.h"
#include "video_source_impl.h"
#include <QMetaType>
#include "cv_ssd.h"

# pragma comment(lib, "secur32.lib")
# pragma comment(lib, "winmm.lib")
# pragma comment(lib, "dmoguids.lib")
# pragma comment(lib, "wmcodecdspuuid.lib")
# pragma comment(lib, "msdmo.lib")
# pragma comment(lib, "Strmiids.lib")
# pragma comment(lib, "User32.lib")

int BubbleSort(int *p,int len){
    if(nullptr ==  p)
        return -1;
    for(int i = 0;i < len - 1;i++){
        for(int j = 0;j < len - 1;j++){
            if(p[j] < p[j + 1]){
                int tmp = p[j];
                p[j] = p[j+1];
                p[j+1] = tmp;
            }
        }
    }
}

void EnumCapture()
{
    rtc::WinsockInitializer winsock_init;
    rtc::Win32SocketServer w32_ss;
    rtc::Win32Thread w32_thread(&w32_ss);
    rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
    rtc::InitializeSSL();

    std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info(
      webrtc::VideoCaptureFactory::CreateDeviceInfo());

    int num_devices = info->NumberOfDevices();
    if (!info) {
        RTC_LOG(LERROR) << "CreateDeviceInfo failed";
        return;
    }
    for (int i = 0; i < num_devices; ++i) {
        char name[128];
        char id[128];

        info->GetDeviceName(i,name,128,id,128,nullptr,0);
        int cap_len = info->NumberOfCapabilities(id);
        for(int j = 0;j < cap_len;j++){
            webrtc::VideoCaptureCapability p;
            info->GetCapability(id,j,p);
            qDebug()<<QString::asprintf("GetCapability:    %s %d %d ",id,p.width,p.height);
        }
        printf("%s\r\n",name);
        //使用索引i创建capture对象
    }
}

int main(int argc, char *argv[])
{
    int p[5] = {3,1,49,23,23};
    BubbleSort(p,5);
    for(int i = 0;i< 5;i++){
        qDebug()<<p[i]<<"  ";
    }
    qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>");
    qRegisterMetaType<rtc::scoped_refptr<webrtc::I420BufferInterface>>("rtc::scoped_refptr<webrtc::I420BufferInterface>&");

    rtc::WinsockInitializer winsock_init;
    rtc::Win32SocketServer w32_ss;
    rtc::Win32Thread w32_thread(&w32_ss);
    rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
    rtc::InitializeSSL();

    setbuf(stdout, NULL);
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication a(argc, argv);
    MainWindow w;
    w.setWindowTitle("learning tool");
    w.show();
    return a.exec();
}




